﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace 控件调整.Common
{
    public class BaseCommand<T> : ICommand
    {
        public Func<T, bool> CanExcuteAction { get; set; }
        public Action<T> ExecuteAction { get; set; }

        public BaseCommand(Func<T, bool> canExcuteAction, Action<T> executeAction)
        {
            CanExcuteAction = canExcuteAction;
            ExecuteAction = executeAction;
        }

        public event EventHandler? CanExecuteChanged;

        public bool CanExecute(object? parameter)
        {
            return parameter == null || CanExcuteAction == null;
        }

        public void Execute(object? parameter)
        {
            ExecuteAction?.Invoke((T)parameter);
        }
    }
}
